package com.hmall.api.sentinel;

import com.hmall.api.client.ItemClient;
import com.hmall.api.dto.ItemDTO;
import com.hmall.api.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

@Slf4j
@Component
public class ItemFallBackFactory implements FallbackFactory<ItemClient> {
    @Override
    public ItemClient create(Throwable cause) {
        return new ItemClient() {
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                log.warn("商品不存在:{}", cause.getMessage());
                return List.of();
            }

            @Override
            public void deductStock(List<OrderDetailDTO> items) {
                log.warn("库存扣减失败:{}", cause.getMessage());
            }
        };
    }
}
